package Loop;

import java.util.*;

/**
 * Enjoy programming!!!
 * 时间： 2021/10/21 -  22:49
 */
public class DoWhile {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.print("How much money will you contribute every year?");
        double payment = in.nextDouble();

        System.out.print("Interest rate in %: ");
        double interestRate = in.nextDouble();

        double balance = 0;
        int year = 0;

        String input;
//        在用户尚未准备退休时更新帐户余额
        do {
//add this year`s payment and interrst
            balance += payment;
            double interst = balance * interestRate / 100;
            balance += interst;


            year++;
//print current balance
            System.out.printf("After year %d, your balance is %,.2f%n", year, balance);

//            ask if ready to retire and get input
            System.out.print("Read to retire?(Y/N)");
            input = in.next();
        }
        while (input.equals("N"));
    }
}
